<?php require_once('../Connections/CrossFit.php'); ?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
  $updateSQL = sprintf("UPDATE Members SET Name=%s, Email=%s, Phone=%s, Address=%s, City=%s, `State`=%s, Zip=%s, Emergency_Contact=%s, Emergency_Contact_Phone=%s WHERE ID=%s",
                       GetSQLValueString($_POST['Name'], "text"),
                       GetSQLValueString($_POST['Email'], "text"),
                       GetSQLValueString($_POST['Phone'], "text"),
                       GetSQLValueString($_POST['Address'], "text"),
                       GetSQLValueString($_POST['City'], "text"),
                       GetSQLValueString($_POST['State'], "text"),
                       GetSQLValueString($_POST['Zip'], "text"),
                       GetSQLValueString($_POST['EmergencyContact'], "text"),
                       GetSQLValueString($_POST['EmergencyContactPhone'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));

  mysql_select_db($database_CrossFit, $CrossFit);
  $Result1 = mysql_query($updateSQL, $CrossFit) or die(mysql_error());

  $updateGoTo = "http://development.crossfit26.com/app/profile/";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}







?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Log Out</title>
</head>

<body>
<center><img src="ajax-loader.gif" width="32" height="32" style="margin-top:150px;"><p>Processing...</p></center>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form" onsubmit="MM_validateForm('Name','','R','Email','','RisEmail','Address','','R','City','','R','State','','R','Zip','','R','Phone','','R','EmergencyContact','','R','EmergencyContactPhone','','R');return document.MM_returnValue">
  <table width="600" border="0">
  <tr>
    <td><label for="Name1">Name </label></td>
    <td><input name="Name" type="text" id="Name" value="<?php echo $row_MemberProfile['Name']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="Email">Email Address</label></td>
    <td><input name="Email" type="text" id="Email" value="<?php echo $row_MemberProfile['Email']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="Address">Address </label></td>
    <td><input name="Address" type="text" id="Address" value="<?php echo $row_MemberProfile['Address']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="City">City </label></td>
    <td><input name="City" type="text" id="City" value="<?php echo $row_MemberProfile['City']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="State">State </label></td>
    <td><input name="State" type="text" id="State" value="<?php echo $row_MemberProfile['State']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="Zip">Zip Code</label></td>
    <td><input name="Zip" type="text" id="Zip" value="<?php echo $row_MemberProfile['Zip']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="Phone">Phone Number </label></td>
    <td><input name="Phone" type="text" id="Phone" value="<?php echo $row_MemberProfile['Phone']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="EmergencyContact">Emergency Contact </label></td>
    <td><input name="EmergencyContact" type="text" id="EmergencyContact" value="<?php echo $row_MemberProfile['Emergency_Contact']; ?>" /></td>
  </tr>
  <tr>
    <td><label for="EmergencyContactPhone">Emergency Contact Phone </label></td>
    <td><input name="EmergencyContactPhone" type="text" id="EmergencyContactPhone" value="<?php echo $row_MemberProfile['Emergency_Contact_Phone']; ?>" /></td>
  </tr>
  <input name="ID" type="hidden" value="<?php echo $row_MemberProfile['ID']; ?>" />
</table>
<p><input name="Submit" type="submit" value="Save" /></p>
<input type="hidden" name="MM_update" value="form" />
</form>
<script type="text/javascript">
<!--
//window.location = "http://development.crossfit26.com/app/profile/"
//-->
</script>
</body>
</html>